import {createRouter,createWebHistory} from 'vue-router'
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path:'/',
            component:()=>import('../views/login.vue'),
        },
        {
            path:'/index',
            name:'layout',
            component:()=>import('../layout/index.vue'),
            meta:{
                flag:true
            },
            children:[
                {
                    path:'/fail',
                    component:()=>import('../views/checkFailFiles.vue'),
                    meta:{
                        flag:false
                    }
                },
                {
                    path:'/xiangqing',
                    component:()=>import('../views/xiangqing.vue'),
                    meta:{
                        flag:false
                    }
                },

            ]
        }
    ],
})

// 路由守卫
router.beforeEach((to, from,next) => {
    if(to.path == "/"){
        return next(true)
    }
    const token = localStorage.getItem("token")
    if(!token){
        return next("/")
    }
    return next(true)
})
export default router